package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.AcCustomerInfo;
import com.ruoyi.business.service.IAcCustomerInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户台账管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-20
 */
@RestController
@RequestMapping("/business/customerInfo")
public class AcCustomerInfoController extends BaseController
{
    @Autowired
    private IAcCustomerInfoService acCustomerInfoService;

    /**
     * 查询客户台账管理列表
     */
//    @PreAuthorize("@ss.hasPermi('business:customerInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AcCustomerInfo acCustomerInfo)
    {
        startPage();
        List<AcCustomerInfo> list = acCustomerInfoService.selectAcCustomerInfoList(acCustomerInfo);
        return getDataTable(list);
    }

    /**
     * 导出客户台账管理列表
     */
//    @PreAuthorize("@ss.hasPermi('business:customerInfo:export')")
    @Log(title = "客户台账管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AcCustomerInfo acCustomerInfo)
    {
        List<AcCustomerInfo> list = acCustomerInfoService.selectAcCustomerInfoList(acCustomerInfo);
        ExcelUtil<AcCustomerInfo> util = new ExcelUtil<AcCustomerInfo>(AcCustomerInfo.class);
        util.exportExcel(response, list, "客户台账管理数据");
    }

    /**
     * 获取客户台账管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('business:customerInfo:query')")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        return success(acCustomerInfoService.selectAcCustomerInfoByCustomerId(customerId));
    }

    /**
     * 新增客户台账管理
     */
//    @PreAuthorize("@ss.hasPermi('business:customerInfo:add')")
    @Log(title = "客户台账管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AcCustomerInfo acCustomerInfo)
    {
        return toAjax(acCustomerInfoService.checkAndInsertAcCustomerInfo(acCustomerInfo));
    }

    /**
     * 修改客户台账管理
     */
//    @PreAuthorize("@ss.hasPermi('business:customerInfo:edit')")
    @Log(title = "客户台账管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AcCustomerInfo acCustomerInfo)
    {
        return toAjax(acCustomerInfoService.updateAcCustomerInfo(acCustomerInfo));
    }

    /**
     * 删除客户台账管理
     */
//    @PreAuthorize("@ss.hasPermi('business:customerInfo:remove')")
    @Log(title = "客户台账管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    @ApiOperation("删除客户信息")
    public AjaxResult remove(@PathVariable Long[] customerIds)
    {
        int result = acCustomerInfoService.checkAndDeleteAcCustomerInfo(customerIds);
        if(0 == result) {
            return AjaxResult.error("不可以删除在租客户！");
        }
        return toAjax(result);
    }

//    @Log(title = "客户台账管理", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{customerIds}")
//    public AjaxResult remove(@PathVariable Long[] customerIds)
//    {
//        return toAjax(acCustomerInfoService.deleteAcCustomerInfoByCustomerIds(customerIds));
//    }

    // ******************************************************************************************************
    @GetMapping("/selectcCustomerInfoList")
    @ApiOperation("不分页查询客户信息")
    public AjaxResult selectcCustomerInfoList(AcCustomerInfo acCustomerInfo)
    {
        List<AcCustomerInfo> list = acCustomerInfoService.selectAcCustomerInfoList(acCustomerInfo);
        return AjaxResult.success(list);
    }
}
